<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>培训信息</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../../../css/mui.min.css">
		<link rel="stylesheet" href="../../../../css/global.css">
		<link rel="stylesheet" href="../../../../css/style.css">
		<link rel="stylesheet" href="../../../../css/mui.picker.css">
		<link rel="stylesheet" href="../../../../css/mui.poppicker.css">
		<style type="text/css">
		   .mui-btn-block{
				font-size: 16px;
				color: #a9a9a9;
				border: 0;
		   }
		   input.d_ipt{
			   padding: 0;
		   }
		   .details_con .clum{
			   display: flex;
		   }
		   .details_con .clum input, .details_con .clum .txt{
			   flex: 1;
		   }
		   .details_con .clum .name{
			   width: 150px;
		   }
		   .details_con .clum .txt button{
			   text-align: right;
		   }
	  </style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">培训信息</h1>
		</header>
		<div class="mui-content" id="mui-content" style="display: none;">
			<div hidden>
				<input type="hidden" id="id" />
				<input type="hidden" id="serviceNo" />
				<input type="hidden" id="enginnerId" />
				<input type="hidden" id="helpId" />
			</div>
			<div class="details_con">
				<div class="clum">
					<span class="name">培训类型</span>
					<input type="hidden" id="trainType" />
					<span class="txt">
						<button id='trainTypeName' class="mui-btn mui-btn-block mui-btn-select" type='button'>请选择</button>
					</span>
				</div>
				<div class="clum">
					<span class="name">参加人数</span>
					<input type="number" id="trainNum" class="d_ipt" placeholder="请输入参加人数" />
				</div>
				<div class="clum">
					<span class="name">参加培训的人员姓名</span>
					<input type="hidden" id="trainFseCode" />
					<input type="text" id="trainFse" class="d_ipt" placeholder="请输入参加培训人员" />
				</div>
				<div class="clum">
					<span class="name">培训总小时数</span>
					<input type="number" id="trainHour" class="d_ipt" placeholder="请输入培训总小时数" />
				</div>
				<div class="clum">
					<span class="name">培训开始时间</span>
					<span class="txt">
						<button id='trainStart' class="selectDate" type='button'>请选择培训开始时间</button>
					</span>
				</div>
				<div class="clum">
					<span class="name">培训结束时间</span>
					<span class="txt">
						<button id='trainEnd' class="selectDate" type='button'>请选择培训结束时间</button>
					</span>
				</div>
				<div class="clum">
					<span class="name">培训地点</span>
					<input type="hidden" id="trainPlace" />
					<span class="txt">
						<button id='trainPlaceName' class="mui-btn mui-btn-block mui-btn-select" type='button'>请选择</button>
					</span>
				</div>
				<div class="clum autoHeight" style="display: none;">
					<span class="name">其他培训地点</span>
					<div class="clear"></div>
					<textarea id="otherPlace" class="textarea" placeholder="请输入其他培训地点"></textarea>
				</div>
				<div class="clum">
					<span class="name">培训对象</span>
					<input type="hidden" id="trainObject" />
					<span class="txt">
						<button id='trainObjectName' class="mui-btn mui-btn-block mui-btn-select" type='button'>请选择</button>
					</span>
				</div>
				<div class="clum">
					<span class="name">培训内容（客户）</span>
					<input type="hidden" id="cusLevel" />
					<span class="txt">
						<button id='cusLevelName' class="mui-btn mui-btn-block mui-btn-select" type='button'>请选择</button>
					</span>
				</div>
				<div class="clum">
					<span class="name">培训级别（FSE）</span>
					<input type="hidden" id="fseLevel" />
					<span class="txt">
						<button id='fseLevelName' class="mui-btn mui-btn-block mui-btn-select" type='button'>请选择</button>
					</span>
				</div>
				<div class="clum">
					<span class="name">总旅途时间(h)</span>
					<input type="number" id="jourHour" class="d_ipt" placeholder="请输入总旅途时间(h)" />
				</div>
				<div class="clum">
					<span class="name">AE工程师姓名</span>
					<input type="text" id="aeFse" class="d_ipt" placeholder="请输入AE工程师姓名" />
				</div>
				<div class="line"></div>
				<div class="btn_box">
					<span id="cancle" class="fl">取消</span>
					<span id="saveBtn" class="fr red">保存</span>
				</div>
				<div style="height: 50px;"></div>
			</div>
		</div>

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../../js/mui.min.js"></script>
		<script src="../../../../js/utils/h.js"></script>
		<script src="../../../../js/constant.js"></script>
		<script src="../../../../js/common.js"></script>
		<script src="../../../../js/utils/base64.js"></script>
		<script src="../../../../js/utils/md5.js"></script>
		<script src="../../../../js/utils/sortMap.js"></script>
		<script src="../../../../js/utils/http.js"></script>
		<script src="../../../../js/app.js"></script>
		<!-- 基础js end -->
		<script src="../../../../js/utils/rolldate.min.js"></script>
		<script src="../../../../js/mui.picker.js"></script>
		<script src="../../../../js/mui.poppicker.js"></script>
		<script type="text/javascript" charset="utf-8">
			/**
			 * 初始化时间控件
			 */
			function initDateTimeControls() {
				// 培训开始时间
				new Rolldate({
					el: '#trainStart',
					format: 'YYYY-MM-DD hh:mm',
					beginYear: 2015,
					endYear: 2050,
					trigger: 'click',
					lang: {
						title: '请选择培训开始时间',
					},
					confirm: function(date) {

					}
				});

				// 培训结束时间
				new Rolldate({
					el: '#trainEnd',
					format: 'YYYY-MM-DD hh:mm',
					beginYear: 2015,
					endYear: 2050,
					trigger: 'click',
					lang: {
						title: '请选择培训结束时间',
					},
					confirm: function(date) {

					}
				});
			}
			
			// 提交状态 0未提交 1已提交
			var submitStatus = 0;
			
			/*
			* 禁止交互事件
			*/
			function noInteraction() {
				if(submitStatus && submitStatus == '1') {
					h('#trainTypeName').attr('disabled', 'disabled')
					h('#trainFse').attr('disabled', 'disabled')
					h('#trainStart').attr('disabled', 'disabled')
					h('#trainEnd').attr('disabled', 'disabled')
					h('#trainPlaceName').attr('disabled', 'disabled')
					h('#trainObjectName').attr('disabled', 'disabled')
					h('#cusLevelName').attr('disabled', 'disabled')
					h('#fseLevelName').attr('disabled', 'disabled')
		
					h('#trainNum').attr('readonly', 'readonly')
					h('#trainHour').attr('readonly', 'readonly')
					h('#otherPlace').attr('readonly', 'readonly')
					h('#jourHour').attr('readonly', 'readonly')
					h('#aeFse').attr('readonly', 'readonly')

					h('#saveBtn').hide()
					h('#cancle').hide()
				}
			}

			(function($, doc) {
				noInteraction()
				$.init();

				$.plusReady(function() {
					var self = plus.webview.currentWebview();
					var wo = self.opener();
					submitStatus = self.submitStatus;
					noInteraction()
					var serviceNo = self.serviceNo;
					h('#id').val(self.serviceReportId);
					h('#serviceNo').val(self.serviceNo);
					h('#enginnerId').val(self.enginnerId);
					h('#helpId').val(self.helpId);
					h('#trainType').val(self.trainType);
					h('#trainTypeName').html(self.trainTypeName || '请选择');
					h('#trainNum').val(self.trainNum);
					h('#trainFse').val(self.trainFse);
					h('#trainFseCode').val(self.trainFseCode);
					h('#trainHour').val(self.trainHour);
					h('#trainStart').html(self.trainStart || '请选择培训开始时间');
					h('#trainEnd').html(self.trainEnd || '请选择培训结束时间');
					h('#trainPlace').val(self.trainPlace);
					h('#trainPlaceName').html(self.trainPlaceName || '请选择');
					h('#otherPlace').val(self.otherPlace);
					h('#trainObject').val(self.trainObject);
					h('#trainObjectName').html(self.trainObjectName || '请选择');
					h('#cusLevel').val(self.cusLevel);
					h('#cusLevelName').html(self.cusLevelName || '请选择');
					h('#fseLevel').val(self.fseLevel);
					h('#fseLevelName').html(self.fseLevelName || '请选择');
					h('#jourHour').val(self.jourHour);
					h('#aeFse').val(self.aeFse);

					h('#mui-content').show();

					initDateTimeControls();
					
					
					// 培训类型
					h('#trainTypeName').tap(function() {
						app.hideSoftKeybord()
						var userPicker = new $.PopPicker();
						userPicker.setData([{
								value: '1',
								text: '内部培训'
							},
							{
								value: '2',
								text: '外部培训'
							}
						]);
						userPicker.show(function(items) {
							h('#trainTypeName').html(items[0].text)
							h('#trainType').val(items[0].value)
							userPicker.dispose()
						});
					});

					// 参加培训的人员姓名
					/*h('#trainFse').tap(function() {
						app.hideSoftKeybord()
						app.jumpTo('trainPersonSelect.html', 'view/service/report/fieldservice/trainPersonSelect.html', {
							serviceNo: h('#serviceNo').val(),
							trainFse: h('#trainFse').val(),
							trainFseCode: h('#trainFseCode').val()
						})
					});*/

					// 培训地点
					h('#trainPlaceName').tap(function() {
						app.hideSoftKeybord()
						var userPicker = new $.PopPicker();
						userPicker.setData([{
								value: '1',
								text: '用户现场'
							},
							{
								value: '2',
								text: '培训中心(上海)'
							},
							{
								value: '4',
								text: '培训中心(北京)'
							},
							{
								value: '5',
								text: '成都 Demo Lab'
							},
							{
								value: '6',
								text: '广州 Demo Lab'
							},
							{
								value: '7',
								text: '代理商处'
							},
							{
								value: '3',
								text: '其他'
							}
						]);
						userPicker.show(function(items) {
							h('#trainPlaceName').html(items[0].text)
							h('#trainPlace').val(items[0].value)
							if (items[0].value === '3') {
								h('#otherPlace').parent().show();
							} else {
								h('#otherPlace').parent().hide();
								h('#otherPlace').val('');
							}
							userPicker.dispose()
						});
					});

					// 培训对象
					h('#trainObjectName').tap(function() {
						app.hideSoftKeybord()
						var userPicker = new $.PopPicker();
						userPicker.setData([{
								value: '1',
								text: '培训班(客户)'
							},
							{
								value: '5',
								text: '培训班(FSE)'
							},
							{
								value: '2',
								text: '培训班(客户&FSE)'
							},
							{
								value: '3',
								text: 'Onjob Training(FSE)'
							},
							{
								value: '4',
								text: 'Onjob Training(Dealer FSE)'
							},
						]);
						userPicker.show(function(items) {
							h('#trainObjectName').html(items[0].text)
							h('#trainObject').val(items[0].value)
							userPicker.dispose()
						});
					});

					// 培训内容 (客户)
					h('#cusLevelName').tap(function() {
						app.hideSoftKeybord()
						var userPicker = new $.PopPicker();
						userPicker.setData([{
								value: '1',
								text: '操作及基础应用'
							},
							{
								value: '2',
								text: '进阶应用培训'
							},
							{
								value: '3',
								text: '高级维护与操作培训'
							},
							{
								value: '4',
								text: '高级应用培训'
							},
							{
								value: '5',
								text: '高级软件培训'
							},
							{
								value: '6',
								text: '现场应用支持'
							},
							{
								value: '7',
								text: '现场培训'
							},
							{
								value: '8',
								text: '应用方法开发'
							},
							{
								value: '9',
								text: '在线培训'
							},
							{
								value: '10',
								text: '免费讲座'
							}
						]);
						userPicker.show(function(items) {
							h('#cusLevelName').html(items[0].text)
							h('#cusLevel').val(items[0].value)
							userPicker.dispose()
						});
					});

					// 培训内容 (FSE)
					h('#fseLevelName').tap(function() {
						app.hideSoftKeybord()
						var userPicker = new $.PopPicker();
						userPicker.setData([{
								value: '1',
								text: '初级'
							},
							{
								value: '2',
								text: '中级'
							},
							{
								value: '3',
								text: '高级'
							},
							{
								value: '4',
								text: 'Basic Training'
							},
							{
								value: '5',
								text: 'Advanced Training'
							},
							{
								value: '6',
								text: 'IQOQ Training'
							},
							{
								value: '7',
								text: 'TTT Training'
							}
						]);
						userPicker.show(function(items) {
							h('#fseLevelName').html(items[0].text)
							h('#fseLevel').val(items[0].value)
							userPicker.dispose()
						});
					});

					// 保存
					h('#saveBtn').tap(function() {
						app.hideSoftKeybord()
						if (!app.getNetworkState()) {
							app.toast("无网络")
							return
						}
						
						var id = h('#id').val();
						var helpId = h('#helpId').val();
						var trainType = h('#trainType').val();
						var trainTypeName = h('#trainTypeName').html();
						var trainNum = h('#trainNum').val() || 0;
						var trainFse = h('#trainFse').val();
						var trainFseCode = h('#trainFseCode').val();
						var trainHour = h('#trainHour').val();
						
						var trainPlace = h('#trainPlace').val();
						var trainPlaceName = h('#trainPlaceName').html();
						var otherPlace = h('#otherPlace').val();
						var trainObject = h('#trainObject').val();
						var trainObjectName = h('#trainObjectName').html();
						var cusLevel = h('#cusLevel').val();
						var cusLevelName = h('#cusLevelName').html();
						var fseLevel = h('#fseLevel').val();
						var fseLevelName = h('#fseLevelName').html();
						var jourHour = h('#jourHour').val();
						var aeFse = h('#aeFse').val();
						var enginnerId = app.getUser().enginnerId;
						var fseName = app.getUser().name;
						
						var trainStart = h('#trainStart').html();
						if (trainStart == '请选择培训开始时间') {
							trainStart = ''
						}
						var trainEnd = h('#trainEnd').html();
						if (trainEnd == '请选择培训结束时间') {
							trainEnd = ''
						}
						
						
						if (trainStart && !trainEnd) {
							app.toast('请选择培训结束时间')
							return;
						}
						
						if (!trainStart && trainEnd) {
							app.toast('请选择培训开始时间')
							return;
						}
						
						if (trainStart && trainEnd) {
							if (stringYYYYMMDDHHMMToDate(trainStart).getTime() > stringYYYYMMDDHHMMToDate(trainEnd).getTime()) {
								app.toast('培训开始时间不能大于培训任务时间')
								return false
							}
						}
							
							
						
						
						var params = {
							id,
							serviceNo,
							helpId,
							enginnerId,
							trainType,
							trainTypeName,
							trainNum,
							trainFse,
							trainFseCode,
							trainHour,
							trainStart,
							trainEnd,
							trainPlace,
							trainPlaceName,
							otherPlace,
							trainObject,
							trainObjectName,
							cusLevel,
							cusLevelName,
							fseLevel,
							fseLevelName,
							jourHour,
							aeFse,
							fseName
						}
						app.showWaiting('正在保存...')
						ajaxPost(BASE_URL + 'cc/service/report/editServiceTrainingInformation', params, function(data) {
							app.closeWaiting();
							if (data.code === 200) {
								app.toast("保存成功")
								params.id = data.data.id
								var args = encodeURI(JSON.stringify(params));
								wo.evalJS('updateTrainInfo("' + args + '")')
								$.back()
							} else {
								if (data.msg) {
									app.toast(data.msg)
								} else {
									app.toast()
								}
							}
						}, function(errorMsg) {
							app.closeWaiting();
							app.toast(errorMsg);
						});
					});

					h('#cancle').tap(function() {
						app.hideSoftKeybord()
						$.back();
					});
				});
			}(mui, document));

			function updatetrainFse(trainFse, trainFseCode) {
				if (!trainFse) {
					app.toast("无培训人员信息")
					return;
				}
				h('#trainFse').val(trainFse);
				h('#trainFseCode').val(trainFseCode);
			}
		</script>
		<!-- js代码 end -->

	</body>

</html>
